#ifndef TMESH_H
#define TMESH_H

#include "../Config/Export.h"
#include "../Core/IDrawable.h"
#include "../Core/Texture.h"
#include "../Core/Model.h"
#include "../Maths/TVector3.h"
#include <vector>

namespace epix {

template<class Drawer>
class SHARED TMesh : public IDrawable, public Drawer
{
    public:
    
		TMesh();
		TMesh(Model *model);
        TMesh(const char *filename);
        virtual ~TMesh();
        
        void load(Model *model);
        void load(const char *filename);

		void genNormals();
		void drawNormals();
		
        void setTexture(Texture *texture);
        void setTexture(const char *filename);

        void setPosition(const Vector3d &pos);
        void setScale(const Vector3d &scale);
        void setRotation(double angle, const Vector3d &rot = Vector3d(0, 1, 0));

        const Vector3d &getPosition();
        const Vector3d &getScale();
        
        virtual void clear();

        virtual void draw();

    private:

        virtual void create();

        TMesh(TMesh&);
        TMesh &operator=(const TMesh &);
	
	protected:
	
        std::vector<Texture*> _textures;
        double _angle;
        Vector3d _pos, _scale, _axes;
        bool _multiTex_ext;
	
		Model *model;
		
		void normcrossprod(float v1[3], float v2[3], float out[3]);
		void createnormal(float *v1, float *v2, float *v3,float *out);
		void addnormal(float *n, float *newnorm);
		void normalize(float v[3]);

};

typedef std::vector<Texture*>::iterator TexIterator;

#include "TMesh.inl"

}

#endif
